package graph;

import java.util.HashMap;

import task_system.Task;
import exception.ImpossibleTaskConfigurationException;

@SuppressWarnings("all")
public abstract class TaskConfiguration {
	public final static int SYSTEM = 0;
	public final static int SCHEDULER = 1;

	protected int c;
	protected int d;
	protected int p;
	protected int owner;

	protected Task task;

	public TaskConfiguration(int p, int d, int c, Task t)
			throws ImpossibleTaskConfigurationException {
	
		if (t == null){
			throw new ImpossibleTaskConfigurationException("Input Task Null !");
		}
		
		if (!t.compatibleConfiguration(p, d, c)){
			throw new ImpossibleTaskConfigurationException(
					"Incompatible configuration" + p + "," + d + "," + c
							+ " with task " + t.P() + "," + t.D() + "," + t.C());
		}

	
		this.c = c;
		this.d = d;
		this.p = p;
		this.task = t;

	}

	public int c() {
		return c;
	}

	public int d() {
		return d;
	}

	public int p() {
		return p;
	}

	public int owner() {
		return owner;
	}

	public Task task() {
		return task;
	}

	public boolean equals(TaskConfiguration tc) {
		if (this.c() == tc.c() && this.d() == tc.d() && this.p() == tc.p()
				&& this.owner() == tc.owner() && this.task.equals(tc.task()))
			return true;
		return false;
	}

	public boolean failure() {
//		if (c != 0 && d == 0)
		if(c > d)
			return true;
		return false;
	}

	public String toString(){
		if (this.failure())
			return "" + p + " " + d + " " + c + " <-- failure task configuration";

		return "" + p + " " + d + " " + c;
	}
	public abstract HashMap<String, TaskConfiguration> successors();

	public abstract HashMap<String, TaskConfiguration> predecessors();
}
